package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.Product;
import com.briup.jz.bean.extend.ProductExtend;
import com.briup.jz.service.IProductService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(description="产品分类")
@Validated
@RestController
@RequestMapping("/product")
public class ProductController {
	@Autowired//注入接口
    private IProductService productService;
	
	//查
    @ApiOperation(value = "查询所有产品分类")
    @GetMapping("query")
    public Message query(String name){
        List<Product> list = productService.query(name);
        return MessageUtil.success(list);
    } //name属性
    
    @ApiOperation(value = "级联查询所有产品分类")
    @GetMapping("queryCascade")
    public Message queryCascade(String name){
        List<ProductExtend> list = productService.queryCascade(name);
        return MessageUtil.success(list);
    }
    // ++ 多对一
    
  //删除
    @ApiOperation(value = "通过id删除")
    @GetMapping("deleteById")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
   
    public Message deleteById(@NotNull Long id){
        productService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
    
  //增 改
    @ApiOperation(value = "保存或更新产品信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "主键",paramType = "form"),
            @ApiImplicitParam(name="name",value = "产品服务类型",paramType = "form",required = true),
            @ApiImplicitParam(name="description",value = "服务类型描述",paramType = "form"),
            @ApiImplicitParam(name="price",value = "价位",paramType = "form"),
            @ApiImplicitParam(name="status",value = "目前状态",paramType = "form"),
            @ApiImplicitParam(name="photo",value = "服务类型封面",paramType = "form"),
            @ApiImplicitParam(name="productCategoryId",value = "产品类型id",paramType = "form"),  
    })
    @PostMapping("saveOrUpdate")
    public Message saveOrUpdate(Product product){
    	productService.saveOrUpdate(product);
        return MessageUtil.success("更新成功");
    }
    
}
